package messagesvc;

import java.net.InetAddress;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication(scanBasePackages = {"cn.ucloud.microsf.messagesvc", "cn.ucloud.microsf.springlib"})
@MapperScan(basePackages = "cn.ucloud.microsf.messagesvc.orm")
@EnableTransactionManagement
@EnableFeignClients(basePackages = "cn.ucloud.microsf.*svc.api")
@Slf4j
public class Application {

  public static void main(String[] args) throws Exception {
    ConfigurableApplicationContext application = SpringApplication.run(Application.class, args);

    Environment env = application.getEnvironment();
    String contextPath = env.getProperty("server.servlet.context-path");
    contextPath = contextPath == null ? "" : contextPath;
    log.info("\n----------------------------------------------------------\n\t" +
            "Application  is running! Access URLs:\n\t" +
            "Local: \t\t http://localhost:{}{}\n\t" +
            "External: \t http://{}:{}{}\n\t" +
            "Doc: \t http://localhost:{}{}/doc.html\n" +
            "----------------------------------------------------------",
        env.getProperty("server.port"),
        contextPath,

        InetAddress.getLocalHost().getHostAddress(),
        env.getProperty("server.port"),
        contextPath,

        env.getProperty("server.port"),
        contextPath
    );
  }

}
